//
//  LBMStatus.swift
//  微博
//
//  Created by 刘保满 on 16/5/24.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

class LBMStatus: NSObject {
    
    //	微博ID
    var id: Int64 = 0
    
    //微博信息内容
    var text: String?
    
    //微博来源
    var source: String?
    
    //	微博创建时间
    var created_at: String?
    
    //这里面又是一个字典
    var user: LBMUser?
    
    //转发字段
    var retweeted_status: LBMStatus?
    
    //配图
    var pic_urls: [LBMPicture]?
    
    //转发
    var reposts_count: Int = 0
    
    //评论
    var comments_count: Int = 0
    
    //赞
    var attitudes_count: Int = 0
    
 
    init(dict: [String: AnyObject]) {
        
        super.init()
        
        setValuesForKeysWithDictionary(dict)
        
    }
    
    //会走这个方法进行赋值
    override func setValue(value: AnyObject?, forKey key: String) {
        
        //在这里把user 字典转模型
        //先根据key 找到user这个字典
        if key == "user" {
            //再判断对应的value是否是字典
            if let dict = value as? [String: AnyObject] {
                
                //字典转模型
                user =  LBMUser(dict: dict)
            }
            
            return
        }
        
        //给转发微博做字典转模型
        if key == "retweeted_status" {
            
            if let dic = value as? [String: AnyObject] {
                
                retweeted_status = LBMStatus(dict: dic)
                
            }
            
            return
            
        }
        
        //给配图做字典转模型
        if key == "pic_urls" {
            
            //最顶层是数组 里面是字典
            if let array = value as? [[String: AnyObject]] {
                
                var temparray = [LBMPicture]()
                
                for item in array {
                    
                    let p = LBMPicture(dict: item)
                    
                    temparray.append(p)
                }
                
                pic_urls = temparray
                
            }
            
            return
            
        }
        
        
        
        super.setValue(value, forKey: key)
    }
    
    
    
    //过滤
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
        
    }
    
    
    
    
    
}
